<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <jsp:useBean id="player" class="pe.lucene.web.myrating.Player" scope="session"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="org.hibernate.Session"%>
<%@page import="pe.lucene.web.myrating.HibernateUtil"%>
<%@page import="org.hibernate.Query"%>
<%@page import="java.util.List"%>
<%@page import="org.hibernate.SQLQuery"%>
<%@page import="java.math.BigDecimal"%>
<%@page import="java.text.NumberFormat"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Average</title>
</head>
<body>


<%
if (player != null && player.isLogged()) {
	Session hbSession = HibernateUtil.currentSession();
	
	SQLQuery sqlQuery = hbSession.createSQLQuery("select avg(rating) from rating where player = :id");
	sqlQuery.setParameter("id", player.getId());
	
	List list = sqlQuery.list();
	int avgResult = 0;
	
	if (list != null) {
		
		
		for (Object obj: list) {
			BigDecimal big = (BigDecimal) obj;
			if (big != null)
				  avgResult = big.intValue();	
		}
		%>
		<table width="235" height="64" background="./image/back_main_avg.png">
		<tr>
		  <td align="center">
			<%
			for (int i = 0; i < avgResult; i++) {
				%><img src="./image/rating_star_avg.png"></img><%
			}
			%>
		  </td>
		</tr>
		<tr>
		  <td align="right">
            <span>Average <%=avgResult%>&nbsp;&nbsp;&nbsp;</span>
		  </td>
		</tr>
	      
		</table>
		<%
	}
}
%>


</body>
</html>